/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package am.aua.renju.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Ara Yeritsian
 */
@Entity
@Table(name = "game")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Game.findAll", query = "SELECT g FROM Game g"),
    @NamedQuery(name = "Game.findById", query = "SELECT g FROM Game g WHERE g.id = :id"),
    @NamedQuery(name = "Game.findByState", query = "SELECT g FROM Game g WHERE g.state = :state"),
    @NamedQuery(name = "Game.findByStartRules", query = "SELECT g FROM Game g WHERE g.startRules = :startRules"),
    @NamedQuery(name = "Game.findByStartDate", query = "SELECT g FROM Game g WHERE g.startDate = :startDate"),
    @NamedQuery(name = "Game.findByTime", query = "SELECT g FROM Game g WHERE g.time = :time"),
    @NamedQuery(name = "Game.findByIsPlayer1White", query = "SELECT g FROM Game g WHERE g.isPlayer1White = :isPlayer1White")})
public class Game implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    //@NotNull
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "state")
    private String state;
    @Basic(optional = false)
    @NotNull
    @Column(name = "start_rules")
    private short startRules;
    @Column(name = "start_date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date startDate;
    @Column(name = "time")
    private Integer time;
    @Column(name = "is_player1_white")
    private Short isPlayer1White;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "gameId")
    private Collection<MoveHistory> moveHistoryCollection;
    @JoinColumn(name = "player2_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Player player2Id;
    @JoinColumn(name = "player1_id", referencedColumnName = "id")
    @ManyToOne
    private Player player1Id;

    public Game() {
    }

    public Game(Integer id) {
        this.id = id;
    }

    public Game(Integer id, String state, short startRules) {
        this.id = id;
        this.state = state;
        this.startRules = startRules;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public short getStartRules() {
        return startRules;
    }

    public void setStartRules(short startRules) {
        this.startRules = startRules;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Integer getTime() {
        return time;
    }

    public void setTime(Integer time) {
        this.time = time;
    }

    public Short getIsPlayer1White() {
        return isPlayer1White;
    }

    public void setIsPlayer1White(Short isPlayer1White) {
        this.isPlayer1White = isPlayer1White;
    }

    @XmlTransient
    public Collection<MoveHistory> getMoveHistoryCollection() {
        return moveHistoryCollection;
    }

    public void setMoveHistoryCollection(Collection<MoveHistory> moveHistoryCollection) {
        this.moveHistoryCollection = moveHistoryCollection;
    }

    public Player getPlayer2Id() {
        return player2Id;
    }

    public void setPlayer2Id(Player player2Id) {
        this.player2Id = player2Id;
    }

    public Player getPlayer1Id() {
        return player1Id;
    }

    public void setPlayer1Id(Player player1Id) {
        this.player1Id = player1Id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Game)) {
            return false;
        }
        Game other = (Game) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "am.aua.renju.entity.Game[ id=" + id + " ]";
    }
    
}
